package keke.ai.code.mother.handle.security;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import keke.ai.code.mother.common.ResultUtils;
import keke.ai.code.mother.enums.SessionEnum;
import keke.ai.code.mother.model.auth.MyUserDetail;
import keke.ai.code.mother.util.WriteJson;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import java.io.IOException;

/**
 * 认证成功处理器
 */
public class AuthenticationSuccessHandlerImpl implements AuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        MyUserDetail principal = (MyUserDetail) authentication.getPrincipal();
        principal.setPassword(null);

        request.getSession().setAttribute(SessionEnum.LOGIN_USER.getCode(), principal);
    }
}
